package main

import (
	"fmt"
	"time"
)

type Box struct {
	Value int
}

func main() {
	ch := make(chan *Box, 10)
	go read(ch)
	go write(ch)

	time.Sleep(5 * time.Second)
}

func read(ch chan *Box) {
	for {
		time.Sleep(2 * time.Second)
		box := <-ch
		fmt.Println(`read`, box.Value)
	}
}

func write(ch chan *Box) {
	box := new(Box)
	ch <- box
	fmt.Println(`write`, box.Value)
	time.Sleep(time.Second)
	box.Value++

}
